#pragma once

#include <map>
#include <fstream>
#include <string>
using namespace std;

#include "data_v.h"

namespace uppg32
{
	class map_ip : public map < string, data_v >
	{
	private:
		void readIp(string filename)
		{
			ifstream in(filename);
			string line;
			while (getline(in, line))
			{
				istringstream iss(line);
				string s;
				getline(iss, s, ' ');
				if (this->find(s) != this->end())
				{
					(*this)[s].numConnections += 1;
				}
				else
				{
					(*this)[s].ipnumber = s;
					(*this)[s].numConnections = 1;
				}
			}
		}
	public:

		map_ip()
		{
			readIp("ip_test.txt");
		}

		map_ip(string filename)
		{
			readIp(filename);
		}

		int getNumConnections(string ip)
		{
			if (this->find(ip) != this->end())
			{
				return (*this)[ip].numConnections;
			}
			else
			{
				return 0;
			}

		}

		~map_ip()
		{
		}
	};
}

